package define;

public enum ComputeResult 
{
	E_FLOOR_CR("floor"),
	E_DOUBLE_CR("double"),
	E_ROUND_CR("round"),
	E_CEIL_CR("ceil"),
	;
	
	private String m_keyword;
	
	private ComputeResult(String keyword)
	{
		m_keyword = keyword;
	}
	
	public String getKeyword()
	{
		return m_keyword;
	}
	
	public static int changeToInt(double number, ComputeResult cr)
	{
		switch(cr) 
		{
		case E_CEIL_CR:
			return (int)Math.ceil(number);
		case E_FLOOR_CR:
			return (int)Math.floor(number);
		case E_ROUND_CR:
			return (int)Math.round(number);
		default:
			return 0;
		}
	}
	
	public static boolean isChangeToInt(ComputeResult cr)
	{
		return cr != E_DOUBLE_CR;
	}
	
	public static ComputeResult getComputeResult(String key)
	{
		for(ComputeResult cr: ComputeResult.values())
		{
			if(cr.getKeyword().compareTo(key) == 0)
			{
				return cr;
			}
		}
		return null;
	}
}
